package com.base.hong.ui.project

import android.os.Handler
import android.view.View
import androidx.core.os.bundleOf
import com.base.hong.adapter.ProjectListAdapter
import com.base.hong.databinding.FragmentListBinding
import com.base.hong.model.ProjectListData
import com.base.hong.ui.WebViewActivity
import com.base.hong.ui.base.BaseListFragment
import com.base.hong.ui.project.viewmodel.ProjectViewModel
import com.htt.base_library.util.startActivity


class ChildProjectFragment :
    BaseListFragment<ProjectListAdapter, ProjectListData, ProjectViewModel, FragmentListBinding>(){

val a=Handler()
    companion object {
        fun newInstance(cid: Int) = ChildProjectFragment().apply {
            arguments = bundleOf("cid" to cid)
        }
    }

    private val cid by lazy { arguments?.getInt("cid") ?: -1 }

    override fun initData() {
        super.initData()
       viewModel.projectList.observe(this){
            onSuccessList(it.datas.toMutableList())
       }
    }

    override fun setEventListener() {
        getAdapter().setOnItemClickListener { adapter, view, position ->
            startActivity<WebViewActivity>("url" to getAdapter().data[position].link)

        }

    }

    override fun lazyLoad() {
        showLoadingDialog("")
       loadData()
    }

    override fun onLoadMoreData(pagerNumber: Int) {
       loadData()
    }

    override fun loadData() {
        viewModel.getProjectList(getPageIndex(),cid)
    }
}